package com.ruoyi.web.controller.lowcode;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.lowcode.domain.LcDirectoryMenu;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lowcode.domain.vo.LcDirectoryMenuVo;
import com.ruoyi.lowcode.domain.bo.LcDirectoryMenuBo;
import com.ruoyi.lowcode.service.ILcDirectoryMenuService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目录菜单
 *
 * @author ruoyi
 * @date 2023-10-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lowcode/directoryMenu")
public class LcDirectoryMenuController extends BaseController {

    private final ILcDirectoryMenuService iLcDirectoryMenuService;

    /**
     * 查询目录菜单列表
     */
    @SaCheckPermission("lowcode:directoryMenu:list")
    @GetMapping("/list")
    public R<List<LcDirectoryMenu>> list(LcDirectoryMenu directoryMenu) {
        return R.ok(iLcDirectoryMenuService.selectDirectoryMenu(directoryMenu));
    }

    /**
     * 导出目录菜单列表
     */
//    @SaCheckPermission("lowcode:directoryMenu:export")
//    @Log(title = "目录菜单", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(LcDirectoryMenuBo bo, HttpServletResponse response) {
//        List<LcDirectoryMenuVo> list = iLcDirectoryMenuService.queryList(bo);
//        ExcelUtil.exportExcel(list, "目录菜单", LcDirectoryMenuVo.class, response);
//    }

    /**
     * 获取目录菜单详细信息
     *
     * @param menuId 主键
     */
    @SaCheckPermission("lowcode:directoryMenu:query")
    @GetMapping("/{menuId}")
    public R<LcDirectoryMenuVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long menuId) {
        return R.ok(iLcDirectoryMenuService.queryById(menuId));
    }

    /**
     * 新增目录菜单
     */
    @SaCheckPermission("lowcode:directoryMenu:add")
    @Log(title = "目录菜单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LcDirectoryMenuBo bo) {
        return toAjax(iLcDirectoryMenuService.insertByBo(bo));
    }

    /**
     * 修改目录菜单
     */
    @SaCheckPermission("lowcode:directoryMenu:edit")
    @Log(title = "目录菜单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LcDirectoryMenuBo bo) {
        return toAjax(iLcDirectoryMenuService.updateByBo(bo));
    }

    /**
     * 删除目录菜单
     *
     * @param menuIds 主键串
     */
    @SaCheckPermission("lowcode:directoryMenu:remove")
    @Log(title = "目录菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] menuIds) {
        return toAjax(iLcDirectoryMenuService.deleteWithValidByIds(Arrays.asList(menuIds), true));
    }
}
